module.exports = {
	toast(title,delay=2000){
		return new Promise((resolve, reject) => {
			uni.showToast({
				title: title,
				icon: 'none',
				duration:delay,
				success() {
					setTimeout(function(){
						clearTimeout();
						resolve();
					},delay);
				}
			 });
		});
	},
	msg(title,delay=2000){
		return new Promise((resolve, reject) => {
			uni.showToast({
				title: title,
				icon: 'none',
				duration:delay,
				success() {
					setTimeout(function(){
						clearTimeout();
						resolve();
					},delay);
				}
			 });
		});
	},
	back(title,delay=2000){
		return new Promise((resolve, reject) => {
			uni.showToast({
				title: title,
				icon: 'none',
				success() {
					setTimeout(function(){
						uni.navigateBack({})
						clearTimeout();
						resolve();
					},delay)
					
				}
			 });
		});
	},
	ask(title,def=false){
		return new Promise((resolve, reject) => {
			if (def){
				resolve()
			}else{
				uni.showModal({
					title: '提示',
					content: title,
					success(res) {
						if (res.confirm) {
							resolve()
						}else if (reject){
							reject();
						}
					}
				});
			}
		});		
	},
	help(title,def=false){
		return new Promise((resolve, reject) => {
			if (def){
				resolve()
			}else{
				uni.showModal({
					title: '提示',
					content: title,
					confirmText:  '我知道了',   
					showCancel: false,  
					success(res) {
						if (res.confirm) {
							resolve()
						}else if (reject){
							reject();
						}
					}
				});
			}
		});		
	},
	alert(title,def=false){
		return new Promise((resolve, reject) => {
			if (def){
				resolve()
			}else{
				uni.showModal({
					title: '提示',
					content: title,
					showCancel: true,  
					success(res) {
						if (res.confirm) {
							resolve()
						}else if (reject){
							reject();
						}
					},
					
				});
			}
		});		
	},
	warn(title,def=false){
		return new Promise((resolve, reject) => {
			if (def){
				resolve()
			}else{
				uni.showModal({
					title: '提示',
					content: title,
					showCancel: false,  
					success(res) {
						if (res.confirm) {
							resolve()
						}else if (reject){
							reject();
						}
					}
				});
			}
		});		
	},	
	error(title,def=false){
		return new Promise((resolve, reject) => {
			if (def){
				resolve()
			}else{
				uni.showModal({
					title: '出错',
					content: title,
					showCancel: false,  
					success(res) {
						if (res.confirm) {
							resolve()
						}else if (reject){
							reject();
						}
					}
				});
			}
		});		
	},
	auto(title,def=false){
		let type='help';
		if (title.indexOf('://')>=0){
			let url = title.split('://');
			type=url[0];
			title = url[1];
		}
		if (type in this){
			return this[type](title,'msg,toast,back'.indexOf(type)>=0?2000:def);
		}else{
			return this.help(title,def);
		}
			
	},
}
